import umiRouter from 'umi/router'
import pathToRegexp from 'path-to-regexp'

import moment from 'moment'
import 'moment/locale/zh-cn'

export config from './config'
export request from './request'
export tools from './tools'
export base64 from './base64'
export ecityTable from './ecityTable'

/**
 * Adjust the router to automatically add the current language prefix before the pathname in push and replace.
 */
const myRouter = { ...umiRouter }
myRouter.push = umiRouter.push;
myRouter.replace = myRouter.replace;
export const router = myRouter

export function pathMatchRegexp(regexp, pathname) {
    return pathToRegexp(regexp).exec(pathname)
}

const routerAddLangPrefix = params => {
    // if (!i18n) {
    //   return params
    // }
    // if (isString(params)) {
    //   params = addLangPrefix(params)
    // } else {
    //   params.pathname = addLangPrefix(params.pathname)
    // }
    console.log(params, 45)
    return params
  }

export function routerFormat(route) {
    const result = []
    // 格式化
    if(Array.isArray(route) && route.length>0){
        route.forEach(item => {
            const {configUrl: path, imgUrl: icon, nodeName: title, pageUrl: component } = item;
            result.push({ path, component, title, icon })
        })
    }
    return result;
}